package com.competition.system.controller;

import com.competition.system.common.model.response.OutPutResult;
import com.competition.system.dao.UserDao;
import com.competition.system.pojo.User;
import com.competition.system.service.AuthService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 身份鉴权
 * @author Lyq
 * @version 1.0
 * @create 2020/12/16 0:57
 */
@RestController
@RequestMapping("/auth/")
public class AuthController {

    private static final Logger LOGGER = LoggerFactory.getLogger(AuthController.class);

    @Autowired
    private AuthService authService;

    @ApiOperation("登录")
    @RequestMapping(value = "login", method = RequestMethod.POST)
    public OutPutResult findMediaMsgOne(@RequestBody Map<String, Object> params) {
        OutPutResult outPutResult = new OutPutResult();
        User user = new User();
        user.setAccount(String.valueOf(params.get("account")));
        user.setPassword(String.valueOf(params.get("password")));
        user.setPower(String.valueOf(params.get("identity")));
        try {
            User userByLogin = authService.findUserByLogin(user);
            if (userByLogin == null){
                outPutResult.setCode("-9999");
                outPutResult.setMsg("用户名或验证码错误！");
            }else {
                Map map = new HashMap();
                map.put("identity", params.get("identity"));
                outPutResult.setData(map);
            }
        }catch (Exception e){
            outPutResult.setCode("-9999");
            outPutResult.setMsg("服务异常！");
            LOGGER.error("获取媒体信息异常:", e);
        }
        return outPutResult;
    }

}
